#include <stdio.h>
#include "string.h"
#define MAX_SIZE 1000

typedef struct {
    char ch[MAX_SIZE];
    int len;
}SeqString;

int find(SeqString *s,SeqString *t){
    int i = 0,j = 0;
    while((i<s->len)&&(j<t->len)){
        if(s->ch[i]==t->ch[j]){
             i++;
             j++;
        }else{
             i=i-j+1;
             j=0;
        }
    }
    if(j==t->len){
        return i-j;
    }
    return 1;
}

//统计英文单词的个数
int number(SeqString *s){
    int count;
    int pre=' ';
    int nowWord;
    for(int i = 0;i<s->len;++i){
        nowWord = s->ch[i];
        if ((pre==' ')&&(nowWord!=' ')){
            count++;
            pre=nowWord;
        }else{
            pre=nowWord;
        }
    }
    return count;
}

//统计某个字符出现的次数
int num(SeqString *s,char target){
    int count;
    for (int i =0;i<s->len;++i){
        if(s->ch[i]==target){
            count++;
        }
    }
    return count;
}

int main(){
    SeqString s,t;
    printf("测试\n");
    strcpy(s.ch,"abcdef");
    number(&s);
    s.len = strlen(s.ch);
    fgets(t.ch, MAX_SIZE, stdin);

    // 移除换行符
    size_t len = strlen(t.ch);
    if (len > 0 && t.ch[len - 1] == '\n') {
        t.ch[len - 1] = '\0';
    }

    t.len = strlen(t.ch);

    // 执行查找
    int pos = find(&s, &t);

    // 输出结果
    if (pos >= 0) {
        printf("模式字符串在主字符串中的位置: %d\n", pos);
    } else {
        printf("未找到模式字符串\n");
    }

    return 0;
}
